Skip to content

QVAC-18418 fix: route bare-crypto and bare-fetch through imports map#1932

Merged
yuranich merged 3 commits into
tetherto:mainfrom
opaninakuffo:fix/rag-bundler-imports-map
May 8, 2026
Merged

QVAC-18418 fix: route bare-crypto and bare-fetch through imports map#1932
yuranich merged 3 commits into
tetherto:mainfrom
opaninakuffo:fix/rag-bundler-imports-map

Conversation

@opaninakuffo

@opaninakuffo opaninakuffo commented May 6, 2026

Copy link
Copy Markdown
Contributor

🎯 What problem does this PR solve?

  • React Native and Expo consumers of @qvac/rag saw SyntaxError: 'LLMChunkAdapter' not exported when loading the package, even though the export exists in source. This was bundle corruption masquerading as a missing export.
  • Root cause: @qvac/rag had raw Bare-specific imports (bare-crypto, bare-fetch) in code paths that non-Bare bundlers may still try to resolve.
  • The old UUID path also depended on uuid-random plus a global crypto mutation, which made import order fragile in runtimes where crypto is not already global.

📝 How does it solve it?

  • Routes Bare/runtime-specific dependencies through package.json#imports:
    • #cryptobare-crypto on Bare, node:crypto on Node, crypto shim for RN/default.
    • #fetchbare-fetch on Bare, fetch shim for Node/RN/default.
  • Updates RAG code to use #crypto / #fetch instead of raw Bare imports.
  • Adds lazy shims that allow bundling to succeed and only throw QvacErrorRAG { DEPENDENCY_REQUIRED } when the missing capability is actually used.
  • Adds crypto-browserify as an optional peer for browser/RN consumers that need Node-style crypto.createHash, especially HyperDB document hashing.
  • Removes uuid-random and the global crypto mutation. generateId() now creates UUID v4 IDs locally using secure randomness from globalThis.crypto.getRandomValues or #crypto.randomBytes/getRandomValues, and throws clearly if neither exists.
  • Updates the RAG example model path handling to use path.resolve.

🧪 How was it tested?

  • npm run lint passes.
  • npm run test:unit passes: 111/111 tests, 599/599 assertions.
  • Added/updated unit coverage for:
    • crypto shim missing/delegated/self-referential behavior
    • fetch shim missing/delegated/default export behavior
    • UUID generation fallback when global crypto is unusable
  • Bundler verification from the original shim work still applies: patched builds resolve through #crypto / #fetch instead of hard-coded bare-crypto / bare-fetch paths.

@opaninakuffo opaninakuffo requested review from a team as code owners May 6, 2026 17:11
Comment thread packages/rag/src/adapters/llm/HttpLlmAdapter.js Outdated
Remove uuid-random and avoid mutating global crypto for ID generation.
Require secure randomness with globalThis.crypto or #crypto fallback.
Add crypto-browserify as an optional peer and clarify crypto/fetch errors.

@yuranich yuranich left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One release hygiene issue: this PR removes uuid-random from packages/rag/package.json, but packages/rag/NOTICE still lists uuid-random@1.3.2. Please regenerate or update the NOTICE before release so the published package attributions match the dependency set.

@yuranich

yuranich commented May 8, 2026

Copy link
Copy Markdown
Contributor

/review

@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

Tier-based Approval Status

**PR Tier:** TIER1

**Current Status:** ✅ APPROVED

**Requirements:**
- 1 Team Member approval ✅ (1/1)
- 1 Team Lead OR Management approval ✅ (1/1)



---
*This comment is automatically updated when reviews change.*

@yuranich yuranich merged commit 451297b into tetherto:main May 8, 2026
6 checks passed
Proletter pushed a commit that referenced this pull request May 24, 2026
…1932)

* fix: route bare-crypto and bare-fetch through imports map

* fix(rag): harden crypto and fetch shims

Remove uuid-random and avoid mutating global crypto for ID generation.
Require secure randomness with globalThis.crypto or #crypto fallback.
Add crypto-browserify as an optional peer and clarify crypto/fetch errors.

---------

Co-authored-by: Yury Samarin <yuri.a.samarin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants